package cn.egame.extraction.multithread.util;

import java.util.Properties;

import cn.egame.common.util.Utils;

public class ConstVar_EFS {
	public static int FETCH_THREAD_NUM = 2; //启动的拉取线程的数目
	public static String MAX_ID_FILE_PATH; //存储当前所有线程准备拉取的最大id的文件地址
	public static String THREAD_FETCH_BASE_FILE_PATH; //每个线程对应的拉取文件地址
	public static String FETCH_ID_URL; //拉取的url
	
	
	
	public static String DAY_FILE_PATH;
	public static String ERROR_IDS_FILE_PATH_404;
	public static String ERROR_IDS_FILE_PATH_500;
	public static String REFETCH_ERROR_IDS_FILE_PATHS="";
	public static String DNS_HOST;
	public static String EFS_TYPE;
	public static String NUM;
//	public static String LOCAL_FILE_PATH;
	public static int REPEAT_READ_NUM;
	public static int END_ID;
	public static String DAY_FILE_TYPE ="";
	
	public static String UPLOAD_ADDRESS;
	public static String UPLOAD_WRITE_ADDRESS;
	
	static{
		Properties properties = getProperties();
		
		FETCH_THREAD_NUM = getPropertiesIntValueByKey(properties, "fetch_thread_num", FETCH_THREAD_NUM);
		System.out.println("fetch_thread_num========"+FETCH_THREAD_NUM);
		
		MAX_ID_FILE_PATH = getPropertiesValueByKey(properties, "max_id_file_path", MAX_ID_FILE_PATH);
		System.out.println("max_id_file_path========"+MAX_ID_FILE_PATH);
		
		THREAD_FETCH_BASE_FILE_PATH = getPropertiesValueByKey(properties, "thread_fetch_base_file_path"
				, THREAD_FETCH_BASE_FILE_PATH);
		System.out.println("thread_fetch_base_file_path========"+THREAD_FETCH_BASE_FILE_PATH);
		
		FETCH_ID_URL = getPropertiesValueByKey(properties, "fetch_id_url", FETCH_ID_URL);
		System.out.println("fetch_id_url========"+FETCH_ID_URL);
		
		
		
		
		
		
		
		DAY_FILE_PATH = getPropertiesValueByKey(properties, "day_file_path", DAY_FILE_PATH);
		System.out.println("day_file_path========"+DAY_FILE_PATH);
		
		ERROR_IDS_FILE_PATH_404 = getPropertiesValueByKey(properties, "error_ids_file_path_404", ERROR_IDS_FILE_PATH_404);
		System.out.println("error_ids_file_path_404========"+ERROR_IDS_FILE_PATH_404);
		
		ERROR_IDS_FILE_PATH_500 = getPropertiesValueByKey(properties, "error_ids_file_path_500", ERROR_IDS_FILE_PATH_500);
		System.out.println("error_ids_file_path_500========"+ERROR_IDS_FILE_PATH_500);
		
		REFETCH_ERROR_IDS_FILE_PATHS = getPropertiesValueByKey(properties, "refetch_error_ids_file_paths", REFETCH_ERROR_IDS_FILE_PATHS);
		System.out.println("refetch_error_ids_file_path========"+REFETCH_ERROR_IDS_FILE_PATHS);
		
		
		DNS_HOST = getPropertiesValueByKey(properties, "dns_host", DNS_HOST);
		System.out.println("dns_host========"+DNS_HOST);
		
		EFS_TYPE = getPropertiesValueByKey(properties, "efs_type", EFS_TYPE);
		System.out.println("efs_type========"+EFS_TYPE);
		
		NUM = getPropertiesValueByKey(properties, "num", NUM);
		System.out.println("num========"+NUM);
		
//		LOCAL_FILE_PATH = getPropertiesValueByKey(properties, "local_file_path", LOCAL_FILE_PATH);
//		System.out.println("local_file_path========"+LOCAL_FILE_PATH);
		
		REPEAT_READ_NUM = getPropertiesIntValueByKey(properties, "repeat_read_num", REPEAT_READ_NUM);
		System.out.println("repeat_read_num========"+REPEAT_READ_NUM);
		
		END_ID = getPropertiesIntValueByKey(properties, "end_id", END_ID);
		System.out.println("end_id========"+END_ID);
		
		DAY_FILE_TYPE = getPropertiesValueByKey(properties, "day_file_type", DAY_FILE_TYPE);
		System.out.println("day_file_type========"+DAY_FILE_TYPE);
		
		/* upload_address 获取 */
		UPLOAD_ADDRESS = getPropertiesValueByKey(properties, "upload_address",
				UPLOAD_ADDRESS);
		System.out.println("upload_address========" + UPLOAD_ADDRESS);
		
		/* upload_address 获取 */
		UPLOAD_WRITE_ADDRESS = getPropertiesValueByKey(properties, "upload_write_address",
		        UPLOAD_WRITE_ADDRESS);
        System.out.println("UPLOAD_WRITE_ADDRESS========" + UPLOAD_WRITE_ADDRESS);
	}
	
	private static String getPropertiesValueByKey(Properties properties,
			String key, String defaultResult) {
		/* download_url 获取 */
		String value = properties.getProperty(key);
		if (value != null && !"".equals(value.trim())) {
			return value;
		}
		return defaultResult;
	}

	private static int getPropertiesIntValueByKey(Properties properties,
			String key, int defaultResult) {
		/* download_url 获取 */
		String value = properties.getProperty(key);
		if (value != null && !"".equals(value.trim()) && value.matches("[-]?\\d+")) {
			return Integer.parseInt(value);
		}
		return defaultResult;
	}
	
	private static Properties getProperties() {
		Properties properties = new Properties();
		try {
			properties = Utils.getProperties("common.properties");
		} catch (Exception e) {
			System.out.println("common.properties not find");
		}
		return properties;
	}
	
	public static void main(String[] args) {
		System.out.println("".matches("[-]?\\d+"));
		
	}
}
